/**
 * Created by Administrator on 2017/6/13.
 */
var qq1 = document.getElementsByClassName("qq1");

var jian = document.getElementsByClassName("jian");

var jia = document.getElementsByClassName("jia");

var jg = document.getElementsByClassName("jg");

var jian1 = document.getElementsByClassName("jian1");

var jia1 = document.getElementsByClassName("jia1");

var jg1 = document.getElementsByClassName("jg1");

var jian2 = document.getElementsByClassName("jian2");

var jia2 = document.getElementsByClassName("jia2");

var jg2 = document.getElementsByClassName("jg2");

var bian = document.getElementsByClassName("bian");
var bian1 = document.getElementsByClassName("bian1");
var bian2 = document.getElementsByClassName("bian2");
var comId= null;
var num= null;

for(let i = 0;i<jia.length;i++){

	if(jg[i].value>0){
		if(comId==null){
    		comId=bian[i].value;
    		
    	}else{
    		comId=comId+"-"+bian[i].value;
    	}
		
		 if(num==null){
	        num=jg[i].value;
	     }else{
	        num=num+"-"+jg[i].value;
	     }
		
	}

    jia[i].onclick = function ()
    {
    	jg[i].value++;
        value.innerHTML++;
    	if(!check(bian[i].value,jg[i].value)){
    		if(comId==null){
        		comId=bian[i].value;
        		
        	}else{
        		comId=comId+"-"+bian[i].value;
        	}
    		if(num==null){
            	num=jg[i].value;
            }else{
            	num=num+"-"+jg[i].value;
            }
    	}
        
        if(value.innerHTML>0){
            yuan.style.display = 'block';
        }
        if(value.innerHTML==0){
            yuan.style.display = 'none';
        }

    };
    jian[i].onclick = function () {
    	if(jg[i].value==0){
    		jg[i].value=0;
    	}else{
    		jg[i].value--; 
    		value.innerHTML--; 
    		if(!check(bian[i].value,jg[i].value)){
        		if(comId==null){
            		comId=bian[i].value;
            		
            	}else{
            		comId=comId+"-"+bian[i].value;
            	}
        		if(num==null){
                	num=jg[i].value;
                }else{
                	num=num+"-"+jg[i].value;
                }
        	}
    		if(value.innerHTML>0){
    			yuan.style.display = 'block';
    		}
	        if(value.innerHTML==0){
	            yuan.style.display = 'none';
	        }
	    }
    };
}


for (let j =0;j<jia1.length;j++){

	if(jg1[j].value>0){
		if(comId==null){
    		comId=bian1[j].value;
    		
    	}else{
    		comId=comId+"-"+bian1[j].value;
    	}
		
		 if(num==null){
	        num=jg1[j].value;
	     }else{
	        num=num+"-"+jg1[j].value;
	     }
		
	}
    jia1[j].onclick = function () {
    	jg1[j].value++;  
    	value.innerHTML++; 
    	if(!check(bian1[j].value,jg1[j].value)){
    		if(comId==null){
        		comId=bian1[j].value;
        		
        	}else{
        		comId=comId+"-"+bian1[j].value;
        	}
    		if(num==null){
            	num=jg1[j].value;
            }else{
            	num=num+"-"+jg1[j].value;
            }
    	}
    	if(value.innerHTML>0){
    		yuan.style.display = 'block';
    	}
        if(value.innerHTML==0){
            yuan.style.display = 'none';
        }
    };
    jian1[j].onclick = function () {
    	if(jg1[j].value==0){
    		jg1[j].value=0;
    	}else{
    		jg1[j].value--;  
    		value.innerHTML--; 
    		if(!check(bian1[j].value,jg1[j].value)){
        		if(comId==null){
            		comId=bian1[j].value;
            		
            	}else{
            		comId=comId+"-"+bian1[j].value;
            	}
        		if(num==null){
                	num=jg1[j].value;
                }else{
                	num=num+"-"+jg1[j].value;
                }
        	}
    		if(value.innerHTML>0){
    			yuan.style.display = 'block';
    		}	
	        if(value.innerHTML==0){
	            yuan.style.display = 'none';
	        }
        }
    };

}
for(let k =0;k<jia2.length;k++){

	if(jg2[k].value>0){
		if(comId==null){
    		comId=bian2[k].value;
    		
    	}else{
    		comId=comId+"-"+bian2[k].value;
    	}
		
		 if(num==null){
	        num=jg2[k].value;
	     }else{
	        num=num+"-"+jg2[k].value;
	     }
		
	}

    jia2[k].onclick = function () {
    	jg2[k].value++;  
    	value.innerHTML++; 
    	if(!check(bian2[k].value,jg2[k].value)){
    		if(comId==null){
        		comId=bian2[k].value;
        		
        	}else{
        		comId=comId+"-"+bian2[k].value;
        	}
    		if(num==null){
            	num=jg2[k].value;
            }else{
            	num=num+"-"+jg2[k].value;
            }
    	}
    	if(value.innerHTML>0){
    		yuan.style.display = 'block';
    	}
        if(value.innerHTML==0){
            yuan.style.display = 'none';
        }};
    jian2[k].onclick = function () {
    	if(jg2[k].value==0){
    		jg2[k].value=0;
    	}else{
    		jg2[k].value--;  
    		value.innerHTML--; 
    		if(!check(bian2[k].value,jg2[k].value)){
        		if(comId==null){
            		comId=bian2[k].value;
            		
            	}else{
            		comId=comId+"-"+bian2[k].value;
            	}
        		if(num==null){
                	num=jg2[k].value;
                }else{
                	num=num+"-"+jg2[k].value;
                }
        	}
    		if(value.innerHTML>0){
    			yuan.style.display = 'block';
    		}
	        if(value.innerHTML==0){
	            yuan.style.display = 'none';
	        }
	    }
    };





}

function check(pan,s){
	if(comId==null){
		return false;
	}
	var ids=comId.split("-");
	var shus=num.split("-");
	var you=false;
	comId=null;
	num=null;
	for (i=0;i<ids.length ;i++ ) 
	{ 
		if(ids[i]==pan){
			shus[i]=s;
			you=true;
		}
		if(comId==null){
	    	comId=ids[i];
	    		
	    }else{
	    	comId=comId+"-"+ids[i];
	    }
		
		if(num==null){
	    	num=shus[i];
	    		
	    }else{
	    	num=num+"-"+shus[i];
	    }
	} 
	
	return you;
}





















qq1[0].onclick = function () {q1.style.display = "block";q2.style.display = "none";q3.style.display = "none";};
qq1[3].onclick = function () {q1.style.display = "block";q2.style.display = "none";q3.style.display = "none";};
qq1[6].onclick = function () {q1.style.display = "block";q2.style.display = "none";q3.style.display = "none";};
qq1[1].onclick = function () {
    q1.style.display = "none";
    q2.style.display = "block";
    q3.style.display = "none";


};
qq1[4].onclick = function () {q1.style.display = "none";q2.style.display = "block";q3.style.display = "none";};
qq1[7].onclick = function () {q1.style.display = "none";q2.style.display = "block";q3.style.display = "none";};
qq1[2].onclick = function () {q1.style.display = "none";q2.style.display = "none";q3.style.display = "block";};
qq1[5].onclick = function () {q1.style.display = "none";q2.style.display = "none";q3.style.display = "block";};
qq1[8].onclick = function () {q1.style.display = "none";q2.style.display = "none";};



//
//function ti(){
//	//alert(comId+"-"+num);
//	var id=document.getElementById("value").value;
//	if(typeof id=="undefined"){
//		alert("请先选择货物！");
//	}else{
//		window.location.href="shop/addCom?id="+comId+"&num="+num; 
//		
//	}
//	
//}


function ti(){
	//alert(comId+"-"+num);
	var id=document.getElementById("value").value;
//	if(typeof id=="undefined"){
//		alert("请先选择货物！");
//	}else{
		window.location.href="shop/addCom?id="+comId+"&num="+num; 
		
//	}
	
}

